// extract module
var http = require('http');
var fs = require('fs');
var socketio = require('socket.io');

//var filename = 'chat.html';
var filename = 'chat.mobile.html';

// create web server
var server = http.createServer(function(request, response) {
	// read html file
	fs.readFile('./resources/' + filename, function(error, data) {
		response.writeHead(200, {'Content-Type': 'text/html'});
		response.end(data);
	});
}).listen(52273, function() {
	console.log('Server running at http://localhost:52273');
});

// create socket server
var io = socketio.listen(server);
io.sockets.on('connection', function(socket) {
	// message event handler
	socket.on('message', function(data) {
		// emit message event to clients
		io.sockets.emit('message', data);
	});
});